package com.mzpai.web.controller;

import java.util.Date;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;
import com.mzpai.board.model.OperateLog;
import com.mzpai.board.service.OperateLogService;
import com.mzpai.board.vo.CollectSeckillProductLogVo;
import com.mzpai.util.BeanUtils;
import com.mzpai.util.DateUtil;
import com.mzpai.util.StringUtils;
import com.mzpai.vo.ResponseVo;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

@Api(value = "看板控制类")
@RestController
@RequestMapping("/operateLog")
public class OperateLogController {
	
	private static final String PLATE_FORM_STORE_ID="0";
	private static final String PLATE_FORM_STORE_NAME="平台";
	
	 protected Logger logger = LoggerFactory.getLogger(OperateLogController.class);

	@Autowired
	private OperateLogService operateLogService;
	
	
	@ApiOperation(value = "收集浏览日志信息")
    @RequestMapping(value = "/saveCollectOperateLog", method = RequestMethod.POST)
    public ResponseVo saveCollectOperateLog(
    		@ApiParam(required = true, name = "operateLog", value = "入参为[OperateLog]对象")
    		@RequestBody OperateLog operateLog ) {
    	    ResponseVo operateCollectRes=new ResponseVo();
    	    operateLog.setCreateTime(DateUtil.getDateNow());
    	    Date careateDate=DateUtil.formatDate(DateUtil.getDateNow().getTime(), DateUtil.DATE);
    	    operateLog.setCreateDate(careateDate);
    	    String storeId=operateLog.getStoreId();
    	    if(StringUtils.isNullOrBlank(storeId)){
    	    	operateLog.setStoreId(PLATE_FORM_STORE_ID);
    	    	operateLog.setStoreName(PLATE_FORM_STORE_NAME);
    	    }
    	    logger.info("msg1=收集浏览日志信息开始,,method=saveCollectOperateLog,,operateLog={}",JSON.toJSONString(operateLog));
		    operateLogService.save(operateLog);
		    logger.info("msg1=收集浏览日志信息结束,,method=saveCollectOperateLog");
    	return operateCollectRes;
    }
	
	
	/*@ApiOperation(value = "收集访问秒杀商品信息")
    @RequestMapping(value = "/collectSeckillProductLog", method = RequestMethod.POST)
    public ResponseVo collectSeckillProductLog(
    		@ApiParam(required = true, name = "operateLog", value = "入参为[OperateLog]对象")
    		@RequestBody CollectSeckillProductLogVo collectSeckillProductLogVo ) {
		
		
    	    ResponseVo operateCollectRes=new ResponseVo();
    	    String storeId=collectSeckillProductLogVo.getStoreId();
    	    if(StringUtils.isNullOrBlank(storeId)){
    	    	collectSeckillProductLogVo.setStoreId(PLATE_FORM_STORE_ID);
    	    	collectSeckillProductLogVo.setStoreName(PLATE_FORM_STORE_NAME);
    	    }
    	    logger.info("msg1=收集访问秒杀商品信息开始,,method=collectSeckillProductLog,,collectSeckillProductLog={}",JSON.toJSONString(collectSeckillProductLogVo));
		   
    	    OperateLog operateLog=new OperateLog();
    	    Date careateDate=DateUtil.formatDate(DateUtil.getDateNow().getTime(), DateUtil.DATE);
    	    operateLog.setCreateDate(careateDate);
    	    operateLog.setCreateTime(DateUtil.getDateNow());;
    	    BeanUtils.copy(collectSeckillProductLogVo, operateLog);
    	    operateLogService.save(operateLog);
		    logger.info("msg1=收集访问秒杀商品信息结束,,method=collectSeckillProductLog");
    	return operateCollectRes;
    }*/
	
	
	/*@ApiOperation(value = "根据用户名称查询操作历史信息")
    @RequestMapping(value = "/selectOperateLogListByUserName", method = RequestMethod.GET)
    public List<OperateLog> selectOperateLogListByUserName(
    		@ApiParam(required = true, name = "userName", value = "入参为[userName]")
    		@RequestParam(value = "userName", required = true) String userName) {
		List<OperateLog> operateLogList = null;//operateLogService.selectOperateLogListByUserName(userName);
    	return operateLogList;
    }
    
	@ApiOperation(value = "根据用户名称分页查询操作历史信息")
    @RequestMapping(value = "/selectOperateLogListPageByUserName", method = RequestMethod.GET)
    public PageInfo<OperateLog> selectOperateLogListPageByUserName(
    		@ApiParam(required = true, name = "userName", value = "入参为[userName]")
    		@RequestParam(value = "userName", required = true) String userName,
    		@ApiParam(required = true, name = "pageNum", value = "入参为当前页[pageNum]")
    		@RequestParam(value = "pageNum", required = true) Integer pageNum,
    		@ApiParam(required = true, name = "pageSize", value = "入参为每页显示数量[pageSize]")
    		@RequestParam(value = "pageSize", required = true) Integer pageSize) {
		PageInfo<OperateLog> operatePageInfo = null;// operateLogService.selectOperateLogListPageByUserName(userName,pageNum,pageSize);
    	return operatePageInfo;
    }*/
	
    
    
	
}
